package com.example;

import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.text.DecimalFormat;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;

public class MyClass {

    public static void main(String[] atgs) {
        try {
            //  设置jar包路径
            ClassPool.getDefault().insertClassPath("C:\\Users\\jsb-cpyy\\.android\\build-cache\\2030bcd23ea81773d567fcf6abc73e326216bcb3\\output\\jars\\classes.jar");

            // 获取需要修改的类
            CtClass testJarClass = ClassPool.getDefault().getCtClass("cn.jpush.android.api.BasicPushNotificationBuilder");
            // 获取类中的printTest方法
            CtMethod printTestMethod = testJarClass.getDeclaredMethod("getNotification");
            // 修改该方法的内容
//            printTestMethod.setBody(" ");
            printTestMethod.insertBefore("{if(android.os.Build.VERSION.SDK_INT>=17)\n" +
                    "                $1.setShowWhen(true);}");

            // 写出到外存中
            testJarClass.writeFile();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private static DecimalFormat df;

    public static String getStr(String str) {
        try {
            if (str == null || "null".equals(str))
                str = "0.00";
            double v = Double.parseDouble(str);
            if (df == null)
                df = new DecimalFormat("0.00");
            return df.format(v);
        } catch (Exception e) {
            e.printStackTrace();
            return str;
        }
    }

    public static String md5(File file) {
        MessageDigest digest = null;
        FileInputStream fis = null;
        byte[] buffer = new byte[1024];

        try {
            if (!file.isFile()) {
                return "";
            }

            digest = MessageDigest.getInstance("MD5");
            fis = new FileInputStream(file);

            while (true) {
                int len;
                if ((len = fis.read(buffer, 0, 1024)) == -1) {
                    fis.close();
                    break;
                }

                digest.update(buffer, 0, len);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

        BigInteger var5 = new BigInteger(1, digest.digest());
        return String.format("%1$032x", new Object[]{var5});
    }
}
